<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue组件8</title>
    <script src="../../js/vue3.js"></script>
    <style>
        #app {
            margin: 2rem auto;
            width: 30%;
        }
        
        p {
            font-size: 1.5rem;
            font-weight: bold;
        }
    </style>
</head>

<body>
    <!-- 运行 -->
    <div id="app">
        <fa></fa>
    </div>
    <!-- 模版 -->
    <template id="fas">
        <h2 >已接收参数: {{getParameter1}}</h2>
        <h2 >已接收参数: {{getParameter2}}</h2>
        <son @set1="getDeliver1" @set2="getDeliver2"></son>
    </template>
    <template id="sons">
       <p>准备发送的参数: {{setParameter1}}</p>
       <p>准备发送的参数: {{setParameter2}}</p>
       <p><button @click="setDeliver">开始发送</button></p>
    </template>
    <script>
        const temp = {
            count: 0
        }
        const v_app = Vue.createApp({
            data() {
                return {}
            },
            components: {
                fa: {
                    template: "#fas",
                    data() {
                        return {
                            getParameter1: "未接收参数",
                            getParameter2: "未接收参数"
                        }

                    },
                    methods: {
                        getDeliver1(value) {
                            this.getParameter1 = value;
                        },
                        getDeliver2(value) {
                            this.getParameter2 = value;
                        }
                    },
                    components: {
                        son: {
                            template: "#sons",
                            data() {
                                return {
                                    setParameter1: "子参数一号",
                                    setParameter2: "子参数二号"
                                }

                            },
                            methods: {
                                setDeliver() {
                                    this.$emit("set1", this.setParameter1);
                                    this.$emit("set2", this.setParameter2);
                                }
                            },
                        }
                    }
                }
            }
        });

        v_app.mount("#app");
    </script>
</body>

</html>